import {
  myRequesy
} from '../../request/api.js'
import paltter from '../../platter/carc'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.data.statusBarHeight);

    console.log(options);
    wx.showLoading({
      title: '海报生成中...',
    })
    let that = this
    let car = new paltter().palette()
    console.log(car,1111);
    console.log(new paltter());
    
    car.views[0].url = options.backImg
    car.views[5].text = options.name + "主题赛"
    // 获取小程序二维码
    myRequesy({
      url: "tag/qrcode",
      data: {
        tag_id: options.id
      }
    }).then(res => {
      if (res.data.code === 0) {
        car.views[12].url = res.data.data.qrcode
        that.setData({
          template: car
        })
        wx.hideLoading()
      }
    })
  },

  saveImg() {
    this.saveImage()
  },
  onImgOK(e) {
    var that = this
    var imagePath = e.detail.path;
    that.setData({
      imagePath: imagePath
    })
  },
  saveImage() {
    var that = this
    wx.saveImageToPhotosAlbum({
      filePath: that.data.imagePath,
      success: (res) => {
        that.setData({
          poster_hidden: true
        })
        wx.showToast({
          title: '已保存到相册',
        })
        setTimeout(() => {
          wx.navigateBack()
        }, 1000)
      },
      fail() {
        wx.showModal({
          title: '保存失败！',
          content: '请检查相册访问是否授权',
          success(res) {
            if (res.confirm) {
              wx.openSetting({
                success(res) {
                  console.log(res.authSetting)
                }
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})